package RECUR_36;

import java.util.HashMap;

public class Solution {
	public boolean isValidSudoku(char[][] board) {
		HashMap<Integer, Integer>[] rows = new HashMap[9];
		HashMap<Integer, Integer>[] cols = new HashMap[9];
		HashMap<Integer, Integer>[] boxs = new HashMap[9];
		for (int i = 0; i < 9; i++) {
			rows[i] = new HashMap<Integer, Integer>();
			cols[i] = new HashMap<Integer, Integer>();
			boxs[i] = new HashMap<Integer, Integer>();
		}
		for (int i = 0; i < board.length; i++) {
			for (int j = 0; j < board.length; j++) {
				if (board[i][j] != '.') {
					int n = (int) board[i][j];
					int index_box = (i / 3) * 3 + (j / 3);
					rows[i].put(n, rows[i].getOrDefault(n, 0) + 1);
					cols[j].put(n, cols[j].getOrDefault(n, 0) + 1);
					boxs[index_box].put(n, boxs[index_box].getOrDefault(n, 0) + 1);

					if (rows[i].get(n) > 1 || cols[j].get(n) > 1 || boxs[index_box].get(n) > 1) {
						return false;
					}

				}

			}
		}
		return true;

	}
}
